package csc420groupproject;

import java.awt.Color;
import javax.swing.Icon;
import javax.swing.JOptionPane;

public class CustomJOptionPane extends JOptionPane {

    private static CustomJOptionPane singleton = null;

    private CustomJOptionPane() {
        //Creates a JOptionPane with a test message
        this.initialize();
    }

    private CustomJOptionPane(Object message) {
        //Creates a instance of JOptionPane to display a message using the plain-message message type and the default options delivered by the UI.
        super(message);
        this.initialize();
    }

    private CustomJOptionPane(Object message, int messageType) {
        //Creates an instance of JOptionPane to display a message with the specified message type and the default options,
        super(message, messageType);
        this.initialize();
    }

    private CustomJOptionPane(Object message, int messageType, int optionType) {
        //Creates an instance of JOptionPane to display a message with the specified message type and options.
        super(message, messageType, optionType);
        this.initialize();
    }

    private CustomJOptionPane(Object message, int messageType, int optionType, Icon icon) {
        //Creates an instance of JOptionPane to display a message with the specified message type, options, and icon.
        super(message, messageType, optionType, icon);
        this.initialize();
    }

    private CustomJOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options) {
        //Creates an instance of JOptionPane to display a message with the specified message type, icon, and options.
        super(message, messageType, optionType, icon, options);
        this.initialize();
    }

    private CustomJOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) {
        //Creates an instance of JOptionPane to display a message with the specified message type, icon, and options, with the initially-selected option specified.
        super(message, messageType, optionType, icon, options, initialValue);
        this.initialize();
    }

    private void initialize() {
        this.setBackground(Color.BLACK);
        this.setForeground(Color.GREEN);
    }

    public static CustomJOptionPane getInstance() {
        if (singleton != null) {
            singleton.setMessage(null);
            singleton.setMessageType(PLAIN_MESSAGE);
            singleton.setOptionType(DEFAULT_OPTION);
            singleton.setIcon(null);
            singleton.setOptions(null);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane());
        }
    }

    public static CustomJOptionPane getInstance(Object message) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(PLAIN_MESSAGE);
            singleton.setOptionType(DEFAULT_OPTION);
            singleton.setIcon(null);
            singleton.setOptions(null);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message));
        }
    }

    public static CustomJOptionPane getInstance(Object message, int messageType) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(messageType);
            singleton.setOptionType(DEFAULT_OPTION);
            singleton.setIcon(null);
            singleton.setOptions(null);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message, messageType));
        }
    }

    public static CustomJOptionPane getInstance(Object message, int messageType,
            int optionType) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(messageType);
            singleton.setOptionType(optionType);
            singleton.setIcon(null);
            singleton.setOptions(null);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message, messageType,
                    optionType));
        }
    }

    public static CustomJOptionPane getInstance(Object message, int messageType,
            int optionType, Icon icon) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(messageType);
            singleton.setOptionType(optionType);
            singleton.setIcon(icon);
            singleton.setOptions(null);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message, messageType,
                    optionType, icon));
        }
    }

    public static CustomJOptionPane getInstance(Object message, int messageType,
            int optionType, Icon icon, Object[] options) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(messageType);
            singleton.setOptionType(optionType);
            singleton.setIcon(icon);
            singleton.setOptions(options);
            singleton.setInitialValue(null);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message, messageType,
                    optionType, icon, options));
        }
    }

    public static CustomJOptionPane getInstance(Object message, int messageType,
            int optionType, Icon icon, Object[] options, Object initialValue) {
        if (singleton != null) {
            singleton.setMessage(message);
            singleton.setMessageType(messageType);
            singleton.setOptionType(optionType);
            singleton.setIcon(icon);
            singleton.setOptions(options);
            singleton.setInitialValue(initialValue);
            return singleton;
        } else {
            return (singleton = new CustomJOptionPane(message, messageType,
                    optionType, icon, options, initialValue));
        }
    }
}
